//
//  CourseDetailController.swift
//  BodyBuilding
//
//  Created by franze on 2017/11/1.
//  Copyright © 2017年 franze. All rights reserved.
//

import UIKit

class CourseDetailController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    var infoDict:NSDictionary?
    var tableView:UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        viewConfig()
    }
    
    func viewConfig(){
        tableView = UITableView(frame: CGRect(x: 0, y: 64, width: WIDTH, height: HEIGHT-64))
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        tableView.delegate = self
        tableView.dataSource = self
        view.addSubview(tableView)
        
        let navBar = CustomNavBar(frame: CGRect(x: 0, y: 0, width: WIDTH, height: 64))
        navBar.initialize(text: "课程详情")
        view.addSubview(navBar)
        
        navBar.backBtn.addTarget(self, action: #selector(back), for: .touchUpInside)
    }
    
    @objc func back(){
        _ = navigationController?.popViewController(animated: true)
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return infoDict?.count ?? 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .value1, reuseIdentifier: "cell")
        var value:String?
        let values = infoDict!.allValues
        if let str = values[indexPath.row] as? String{
            value = str
        }
        let keys = infoDict!.allKeys
        let key = keys[indexPath.row] as! String
        cell.textLabel?.text = "\(key) : \(String(describing: value))"
        return cell
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}
